<template>
  <div class="pageContent">
    <!-- 搜索 -->
    <searchView ref="searchView" @searches="searches" />
    <!-- 表格 -->
    <temlist
      ref="temlist"
      style="margin: 2vw 0 0"
      :data="data"
      :loading="loading"
      @deletes="deletes"
    />
    <!-- 分页器 -->
    <el-pagination
      class="pagination"
      layout="slot,prev, pager, next"
      :total="pag.total"
      :current-page="pag.pageNo"
      :page-size="pag.pageSize"
      @current-change="handleCurrentChange"
    >
      <template slot="default">
        <div>
          <span>总共{{ pag.total }}条</span>
        </div>
      </template>
    </el-pagination>
  </div>
</template>

<script>
import temlist from "./module/temlist.vue";
import searchView from "./module/searchView.vue";
export default {
  components: {
    searchView,
    temlist,
  },
  data() {
    return {
      pag: {
        pageNo: 1,
        pageSize: 5,
        total: 0,
      },
      data: [],
      loading: false,
    };
  },
  created() {
    this.getlist({ pageNo: 1, pageSize: 5 });
  },
  methods: {
    getlist(e) {
      this.loading = true;
      this.$http.get("/allNotice", { params: e }).then((res) => {
        console.log(res, "res");
        if (res.code == 200) {
          setTimeout(() => {
            this.data = res.data.data;
            this.pag.total = res.data.total;
            this.loading = false;
          }, 2000);
        }
      });
    },
    handleCurrentChange(e) {
      this.pag.pageNo = e;
      let obj = {
        pageNo: this.pag.pageNo,
        pageSize: 5,
      };
      this.getlist(obj);
    },
    //搜索结果
    searches(e) {
      let obj = {
        pageNo: 1,
        pageSize: 5,
      };
      obj = Object.assign(obj, e);
      this.getlist(obj);
    },
    //删除
    deletes(e) {
      this.$http.get("/deleteNotice", { params: { id: e.id } }).then((res) => {
        if (res.code == 200) {
          this.getlist({ pageNo: 1, pageSize: 5 });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("../../styles/pages.scss");
</style>